#ifndef __VE_CORE_POOL_H__
#define __VE_CORE_POOL_H__

typedef struct
{
	char *free_chunk;
	int   chunk_size;
	int   chunk_count;
} VEPool;

void ve_pool_init( VEPool *pool, void *data, int chunk_size, int chunk_count );
void * ve_pool_alloc( VEPool *pool );
void ve_pool_free( VEPool *pool, void *data );

#define VE_DEFINE_STATIC_POOL(TypeName,MaxInstances) \
	static TypeName g_mem_##TypeName[MaxInstances]; \
	static VEPool   g_pool_##TypeName = { 0, 0, 0 }; \
	static TypeName * ve_pool_alloc_##TypeName() \
	{ \
		if( !g_pool_##TypeName.chunk_size ) \
			ve_pool_init( &g_pool_##TypeName, g_mem_##TypeName, sizeof(TypeName), MaxInstances ); \
		return (TypeName*)ve_pool_alloc( &g_pool_##TypeName ); \
	} \
	static void ve_pool_free_##TypeName( TypeName *data ) \
	{ \
		ve_pool_free( &g_pool_##TypeName, data ); \
	}

#endif /* __VE_CORE_POOL_H__ */
